package com.share.lottery.activity.personal;


import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;

import com.lidroid.xutils.BitmapUtils;
import com.lidroid.xutils.bitmap.BitmapDisplayConfig;
import com.lidroid.xutils.bitmap.callback.BitmapLoadCallBack;
import com.lidroid.xutils.bitmap.callback.BitmapLoadFrom;
import com.share.lottery.R;
import com.share.lottery.activity.caibotools.SeachGridFragment;
import com.share.lottery.base.BaseFragment;
import com.share.lottery.fragment.HomeFragment;
import com.share.lottery.model.User;
import com.share.lottery.utils.AppUtils;

public class PersonFrgment extends BaseFragment{
	private TextView tvGzs;//关注数
	private TextView tvFss;//粉丝数
	private TextView tvZps;//照片数
	private TextView tvCity;//城市
	private TextView tvBabyOld;//宝宝年龄
	private TextView tvNikeName;//昵称和性别
	private TextView tvZy;//职业
	private ImageView imgHead;
	private ImageView imgGrid;
	private ImageView imgList;
	private ImageView imgSetting;
	private HomeFragment listFragment;
	private MySettingFragment setTingFragment;
	private SeachGridFragment gridFragment;
	private FrameLayout frameLayout;
	private View view;
	private TextView tvGz;//关注按钮
	private BitmapUtils bitmapUtils;
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		view = inflater.inflate(R.layout.person, container,false);
		if (bitmapUtils == null) {
			bitmapUtils = new BitmapUtils(getActivity());
		}
		init();
		return view;
	}
	public void findView() {
		frameLayout = (FrameLayout) view.findViewById(R.id.frame_parent);

		imgHead  = (ImageView) view.findViewById(R.id.img_head);
		imgGrid  = (ImageView) view.findViewById(R.id.tv_grid);
		imgList  = (ImageView) view.findViewById(R.id.tv_list);
		imgSetting  = (ImageView) view.findViewById(R.id.tv_seting);

		tvGz = (TextView) view.findViewById(R.id.tv_gz);
		tvGzs  = (TextView) view.findViewById(R.id.tv_zans);
		tvFss  = (TextView) view.findViewById(R.id.tv_pls);
		tvZps  = (TextView) view.findViewById(R.id.tv_fxs);
		tvCity  = (TextView) view.findViewById(R.id.tv_city);
		tvBabyOld  = (TextView) view.findViewById(R.id.tv_baby_old);
		tvNikeName  = (TextView) view.findViewById(R.id.tv_nike_name);
		tvZy  = (TextView) view.findViewById(R.id.tv_zy); 
	}

	public void getData() {
		if (listFragment == null) {
			listFragment = new HomeFragment();
		}
		if (gridFragment == null) {
			gridFragment = new SeachGridFragment();
		}
		if (setTingFragment == null) {
			setTingFragment = new MySettingFragment();
		}
	}



	public void setData() {
		User user = AppUtils.getUserBean();
		if (user != null) {
			bitmapUtils.display(imgHead, user.getAvatar(), new BitmapLoadCallBack<View>() {

				@Override
				public void onLoadCompleted(View container, String uri,
						Bitmap bitmap, BitmapDisplayConfig config,
						BitmapLoadFrom from) {
					((ImageView)container).setImageBitmap(bitmap);

				}


				public void onLoadFailed(View container, String uri,
						Drawable drawable) {
					((ImageView)container).setImageResource(R.drawable.man_defalut);

				}
			});

			tvNikeName.setText(user.getNickname());
			if ("F".equals(user.getGender())) {
				setImg(R.drawable.man, tvNikeName);
			}else if ("M".equals(user.getGender())){
				setImg(R.drawable.wman, tvNikeName);
			}
			
			

		}

	}

	private void setImg(int myid,TextView textview1){
		Drawable nav_up=getResources().getDrawable(myid);  
		nav_up.setBounds(0, 0, nav_up.getMinimumWidth(), nav_up.getMinimumHeight());  
		textview1.setCompoundDrawables(null, null, nav_up, null); 

	}

	private void showChildFrgment(Fragment fragment){
		FragmentManager fm = getChildFragmentManager();
		FragmentTransaction ft = fm.beginTransaction();
		ft.replace(R.id.frame_parent, fragment);
		ft.commit();
	}
	public void setOnClicker() {
		imgHead.setOnClickListener(this);
		imgGrid.setOnClickListener(this);
		imgList.setOnClickListener(this);
		imgSetting.setOnClickListener(this);
		imgGrid.performClick();
	}

	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.img_head://头像更改

			break;
		case R.id.tv_grid://grid方式显示
			showChildFrgment(gridFragment);
			break;
		case R.id.tv_list://list方式显示
			showChildFrgment(listFragment);
			break;
		case R.id.tv_seting://设置
			showChildFrgment(setTingFragment);
			break;

		default:
			break;
		}

	}

}
